/*
 * Viewer.h
 *
 *  Created on: 26.01.2010
 *      Author: Admin
 */

#ifndef VIEWER_H_
#define VIEWER_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inkview.h"
#include "Log.h"

#define FIT_NOT					0							// Disable fit
#define FIT_WIDTH 				1							// Fit by width
#define FIT_HEIGHT 				2							// Fit by height
#define FIT_BOTH 				(FIT_WIDTH | FIT_HEIGHT)	// Fit by both
#define FIT_OVERSIZE			4							// Fit if oversize only

#define DIRECTION_UP			1
#define DIRECTION_DOWN			2
#define DIRECTION_LEFT			4
#define DIRECTION_RIGHT			8
#define DIRECTION_HORIZONTAL	(DIRECTION_LEFT | DIRECTION_RIGHT)
#define DIRECTION_VERTICAL		(DIRECTION_UP | DIRECTION_DOWN)
#define DIRECTION_ALL			(DIRECTION_VERTICAL | DIRECTION_HORIZONTAL)

/* Use defines in infview.h
#define ALIGN_NONE				0
#define ALIGN_LEFT				1
#define ALIGN_CENTER			2
#define ALIGN_RIGHT				3
#define ALIGN_TOP				4
#define ALIGN_MIDDLE			8
#define ALIGN_BOTTOM			12
*/

#define MOVESTEP_25			0.25
#define MOVESTEP_50			0.5
#define MOVESTEP_80			0.8
#define MOVESPET_SCREEN		1.0

const double DEFSCALELINE[] = { .10, .25, .50, .75, 1.00, 1.25, 1.50, 2.00, 3.00, 0 };
const irect  DEFCLIPRECT 	= { 0, 0, 600, 800, 0 };

class Viewer
{
private:
	double* _scaleline;
	ibitmap* _image;
	double _scale, _fitscale, _movestep;
	irect _cliprect, _imagerect;
	int _fitmode;
	void CalcFitScale();
public:
	Viewer();
	~Viewer();

	void SetClipRect(irect* r){_cliprect = *r;}
	void SetClipRect(int x, int y, int w, int h);
	irect GetClipRect(){return _cliprect;}
	irect GetImageRect(){return _imagerect;}

	void SetImage(ibitmap* bit);

	double GetScale(){return _scale;}
	void SetScale(double scale);
	void SetScaleline(double* scaleline){_scaleline = scaleline;}
	double* GetScaleline(){return _scaleline;}

	bool CanZoomIn();
	bool CanZoomOut();
	void ZoomIn();
	void ZoomOut();
	void Zoom100(){SetScale(1.0);}
	void ZoomFit(){SetScale(_fitscale);}
	void Zoom(int num);

	void SetFitMode(int mode){_fitmode = mode; CalcFitScale();}
	int GetFitMode(){return _fitmode;}

	bool CanMove(int dx, int dy);
	void Move(int dx, int dy);
	void SetMoveStep(double step){_movestep = step < 0 ? 0 : step > 1 ? 1 : step;}
	double GetMoveStep(){return _movestep;}
	bool CanMoveDirection(int direction);
	void MoveDirection(int direction);
	void MoveAlign(int align);

	void Draw();
};

#endif /* VIEWER_H_ */
